import request from '@/utils/request'

const loginApi = {
  // userLogin: '/api/auth/user/login',
  userLogin: '/User/login/',
  userRegister: '/api/auth/user/register',
  sendCaptcha: '/api/auth/email/sendCaptcha',
  forgetPassword: '/api/auth/email/forgot-password',
  resetPassword: `/api/auth/user/reset-password`,
  permissionRoutes: '/api/auth/permission/routes',
  userInfo: '/User/getrole/',
  tablelist_data:"/User/user/"
}

class Service {
  /**
   * @description POST 用户登录接口
   */
  static postLogin(data: any) {
    return request({
      url: loginApi.userLogin,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
        return res
    })
  }

  /**
   * @descript POST  用户注册
   */
  static postRegister(data: any) {
    return request({
      url: loginApi.userRegister,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      if (res.status === 0) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /**
   * @description   POST 发送验证码 /auth/email/sendCaptcha
   */
  static postCaptcha(data: any) {
    return request({
      url: loginApi.sendCaptcha,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      if (res.status === 0) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /**
   * @description POST 忘记密码接口
   */
  static postForgetPwd(data: any) {
    return request({
      url: loginApi.forgetPassword,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      if (res.status === 0) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /**
   * @description /auth/user/reset-password/{token}
   */
  static postResetPwd(data: any) {
    return request({
      url: loginApi.resetPassword,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      if (res.status === 0) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /**
   * @description POST 保存授权菜单权限
   */
  static postAuthPermission(data: any) {
    return request({
      url: loginApi.permissionRoutes,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      console.log(res)
      if (res.status === 0) {
        return Promise.resolve(res)
      }
      return Promise.reject(res)
    })
  }

  /**
   * @description POST 查询用户信息
   */

  static postAuthUserInfo(data: any) {
    return request({
      url: loginApi.userInfo,
      method: 'POST',
      json: true,
      data
    }).then((res) => {
      return res
    })
  }
  
  //获取用户的数据
  static tablelist_datas(){
    return request({
      url:loginApi.tablelist_data,
      method:'get',
      json:true,
    }).then((res)=>{
      return res
    })
  }
  //删除用户数据
  static tablelist_del(id:any){
    return request({
      url:`/User/user/${id}`,
      method:'delete',
      json:true,
    }).then((res)=>{
      return res
    })
  }
  //修改用户数据
  static tablelist_put(data:any){
    return request({
      url:`/User/user/${data.id}`,
      method:'put',
      json:true,
      data
    }).then((res)=>{
      return res
    })
  }
  //添加用户数据
  static tablelist_tj(data:any){
    return request({
      url:`/User/user/`,
      method:'post',
      json:true,
      data
    }).then((res)=>{
      return res
    })
  }
  //获取权限数据
  static tablelist_qxhq(){
    return request({
      url:`/User/role/`,
      method:'get',
      json:true
    }).then((res)=>{
      return res
    })
  }
  //用户分配权限
  static tablelist_qxfp(data:any){
    return request({
      url:`/User/user/`,
      method:'post',
      json:true,
      data
    }).then((res)=>{
      return res
    })
  }

}
export default Service
